package LeetCode;

public class LC_566_ReshapetheMatrix {

    public static void main(String[] args) {

    }

    class Solution {
        public int[][] matrixReshape(int[][] nums, int r, int c) {
            int original_r = nums.length;
            int original_c = nums[0].length;
            if (original_r * original_c == r * c) {
                int[][] result = new int[r][c];
                for (int i = 0; i < r * c; i++) {
                    result[i / c][i % c] = nums[i / original_c][i % original_c];
                }
                return result;
            } else {
                return nums;
            }
        }
    }

}